package top.mengchaob.deploy.service;

import top.mengchaob.deploy.api.HostServiceI;
import top.mengchaob.deploy.jpa.HostRepository;
import top.mengchaob.deploy.table.HostDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @title：
 * @author: mengchaob
 * @date: 2021年04月28日 23:10
 * @description:
 */
@Service
public class HostService implements HostServiceI {
    @Autowired
    HostRepository hostRepository;

    @Override
    public void add(HostDo hostDo) {
        hostRepository.save(hostDo);
    }

    @Override
    public void del(String ids) {
        String[] strings = ids.split(",");
        hostRepository.deleteByIds(Arrays.asList(strings.clone()));
    }

    @Override
    public void update(HostDo hostDo) {
        hostRepository.save(hostDo);
    }

    @Override
    public List<HostDo> queryAll() {
        Sort sort = Sort.by(Sort.Direction.DESC,"createTime");
        return hostRepository.findAll(sort);
    }

    @Override
    public HostDo queryById(HostDo hostDo) {
        return hostRepository.getOne(hostDo.getId());
    }
}
